package com.dsr.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的配置类
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("flower") //分组名称，如果想设置多个，那么可以使用多个@Bean
                .select() //开始过滤（哪些接口会输出文档）
                //为所有接口都生成Api接口文档
                //.apis(RequestHandlerSelectors.any())
                //给带有@Api注解的Controller生成Api接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                //给带有@ApiOperation注解的方法生成Api接口文档
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //给xi.zhou.controller包下面的接口生成Api文档
//                .apis(RequestHandlerSelectors.basePackage("xi.zhou.controller"))
                //可以根据url路径过滤哪些请求生成Api文档
                .paths(PathSelectors.any())
                .build();
    }

    //接口文档的描述信息
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("Swagger") //设置文档标题
                .description("flowerSwagger")
                .version("1.0.0")
//                .termsOfServiceUrl("http://xiaowantong.xyz")// 可用于设置文档的 Licence 信息
                .build();
    }

}